package com.buer.storage.controller;


import com.buer.storage.dto.DepartmentDto;
import com.buer.storage.entity.Department;
import com.buer.storage.service.DepartmentService;
import com.buer.storage.vo.R;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

//库位管理
@RestController
@RequestMapping("/department")
public class DepartmentController {
    @Resource
    private DepartmentService departmentService;

    //增加库位
    @PostMapping("/add.do")
    public R add(@RequestBody DepartmentDto departmentDto) {
        if(departmentService.add(departmentDto) >0){
            return R.setR(1, "添加库位成功", null);
        }
        return R.setR(0, "添加库位成功", null);
    }

    //删除库位
    @GetMapping("/delete.do")
    public R delete(Integer departmentId) {
        if (departmentService.delete(departmentId) > 0) {
            return R.setR(1, "删除库位成功", null);
        }
        return R.setR(0, "删除库位失败", null);
    }

    //修改库位
    @PostMapping("/update.do")
    public R update(@RequestBody DepartmentDto departmentDto){
        if (departmentService.update(departmentDto)>0){
            return R.setR(1,"修改库位成功",null);
        }
        return R.setR(0,"修改库位失败",null);
    }

    //查询所有库位
    @GetMapping("/select.do")
    public List<Department> select(){
        return departmentService.select();
    }
}
